;;;Writes a listing of block names and the layers they use to BLKLAY.LST
;;;
;;;	Author:
;;;		Henry C. Francis
;;;		425 N. Ashe Street
;;;		Southern Pines, NC 28387
;;;
;;;	http://www.paracadd.com
;;;	All rights reserved.
;;;
(defun c:blklay ( / bl_lst)
  (setq tblstrt T bl_lst nil)
  (setq ofil (open "blklay.lst" "w"))
  (setq fname (getvar"dwgname"))
  (while (wcmatch fname "\\")
    (setq fname (substr fname 2))
  )
  (write-line (strcat "Block name/Layer listing for: "(getvar"dwgprefix")fname)ofil)
  (while
    (setq blk1 (tblnext "block" tblstrt))
    (setq bl_lst nil)
    (setq val -2)
    (write-line (cdr(assoc 2 blk1)) ofil)
    (while
      (and
        (entnext(cdr(assoc val blk1)))
        (/= "SEQEND" (cdr(assoc 0(entget(entnext(cdr(assoc val blk1)))))))
      )
      (setq blk1 (entget(entnext(cdr(assoc val blk1)))))
      (if bl_lst
        (if (member (cdr(assoc 8 blk1)) bl_lst)
          nil
          (setq bl_lst (append bl_lst (list(cdr(assoc 8 blk1)))))
        )
        (setq bl_lst (list(cdr(assoc 8 blk1))))
      )
;      (princ (cdr(assoc 8 blk1)))
;      (princ "\n")
;      (if bl_lst
;        (if (member (cdr(assoc 8 blk1)) bl_lst)
;          nil
;          (progn
;            (princ (cdr(assoc 8 blk1)))
;            (princ " ")
;          )
;        )
;      )
      (setq val -1)
    )
;    (princ bl_lst)
    (foreach n bl_lst
      (if(eq(type n)'STR)
        (write-line (strcat "    " n) ofil)
      )
    )
    (princ "\n")
    (setq tblstrt nil)
    (write-line "" ofil)
  )
  (close ofil)
)